import { hookDesign } from "@/hooks/hookDesign";
import persistedstate, { createPersistedState, PersistedStateOptions } from "pinia-plugin-persistedstate";

const { getPrefixCls } = hookDesign();

/**
 * 默认持久存储插件
 */
export const persistedstateDefault = persistedstate;
/**
 * 自定义持久存储插件
 */
export const persistedStateCustom = createPersistedState({
    key: (id) => `sfx_2023_persisted_${id}`,
    storage: localStorage, // sessionStorage,
    // storage: sessionStorage,
    auto: false,
});

/**
 * @description pinia 持久化参数配置
 * @param {String} _key 存储到持久化的 name
 * @param {Array} _paths 需要持久化的 state name
 * @return {PersistedStateOptions}persist 持久选项
 * */
export const persistedStateConfig = (_key: string, _paths?: string[]) => {
    // 持久选项参数
    const persistConfig: PersistedStateOptions = {
        key: _key,
        paths: _paths,
        storage: localStorage, // sessionStorage
    };
    return persistConfig;
};

/**
 * useAppStore  的 ID
 */
export const StoreID = {
    /** 应用存储 */
    APP_STORE: getPrefixCls("AppStore"),
    /** 用户存储 */
    USER_STORE: getPrefixCls("UserStore"),
    /** 身份存储 */
    AUTH_STORE: getPrefixCls("AuthStore"),
    /** 本地存储 */
    LOCALE_STORE: getPrefixCls("LocaleStore"),
    /**  */
    KEEP_ALIVE_STORE: getPrefixCls("KeepAliveStore"),
    /**  */
    TABS_STORE: getPrefixCls("TabsStore"),
};
